
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <title>ReactDOM.render · React源码解析</title>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.0">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-theme-api/theme-api.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../../styles/website.css">
        
    
        
    
        
    
        
    
        
    
        
    

         
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="set-state.html" />
    
    

<script
  async
  src="https://www.googletagmanager.com/gtag/js?id=UA-49483742-5"
></script>
<script>
  window.dataLayer = window.dataLayer || []
  function gtag() {
    dataLayer.push(arguments)
  }
  gtag('js', new Date())

  gtag('config', 'UA-49483742-5')
</script>

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    首页
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" >
            
                <span>
            
                    
                    基础
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../api/react.html">
            
                <a href="../api/react.html">
            
                    
                    React API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../api/react-element.html">
            
                <a href="../api/react-element.html">
            
                    
                    ReactElement
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../api/react-children.html">
            
                <a href="../api/react-children.html">
            
                    
                    React Children
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../api/react-structure.html">
            
                <a href="../api/react-structure.html">
            
                    
                    React 中的数据结构
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                    创建更新
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.3.1" data-path="react-dom-render.html">
            
                <a href="react-dom-render.html">
            
                    
                    ReactDOM.render
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="set-state.html">
            
                <a href="set-state.html">
            
                    
                    setState & forceUpdate
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="expiration-time.html">
            
                <a href="expiration-time.html">
            
                    
                    expirationTime 计算
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    任务调度
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../flow/scheduler-global.html">
            
                <a href="../flow/scheduler-global.html">
            
                    
                    全局变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../flow/schedule-work.html">
            
                <a href="../flow/schedule-work.html">
            
                    
                    scheduleWork
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../flow/scheduler-pkg.html">
            
                <a href="../flow/scheduler-pkg.html">
            
                    
                    react-scheduler
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../flow/perform-work.html">
            
                <a href="../flow/perform-work.html">
            
                    
                    performWork
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../flow/perform-unit-of-work.html">
            
                <a href="../flow/perform-unit-of-work.html">
            
                    
                    performUnitOfWork
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../flow/render-root.html">
            
                <a href="../flow/render-root.html">
            
                    
                    renderRoot
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.6.1" data-path="../flow/render-root/throw-exception.html">
            
                <a href="../flow/render-root/throw-exception.html">
            
                    
                    throwException
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="../flow/begin-work.html">
            
                <a href="../flow/begin-work.html">
            
                    
                    beginWork
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.7.1" data-path="../flow/begin-work/mount-indeterminate-component.html">
            
                <a href="../flow/begin-work/mount-indeterminate-component.html">
            
                    
                    mountIndeterminateComponent
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.2" data-path="../flow/begin-work/mount-lazy-component.html">
            
                <a href="../flow/begin-work/mount-lazy-component.html">
            
                    
                    mountLazyComponent
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.3" data-path="../flow/begin-work/update-functional-component.html">
            
                <a href="../flow/begin-work/update-functional-component.html">
            
                    
                    updateFunctionalComponent
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.4" data-path="../flow/begin-work/update-class-component.html">
            
                <a href="../flow/begin-work/update-class-component.html">
            
                    
                    updateClassComponent
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.5" data-path="../flow/begin-work/update-host-root.html">
            
                <a href="../flow/begin-work/update-host-root.html">
            
                    
                    updateHostRoot
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.6" data-path="../flow/begin-work/update-host-component.html">
            
                <a href="../flow/begin-work/update-host-component.html">
            
                    
                    updateHostComponent
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.7" data-path="../flow/begin-work/update-host-text.html">
            
                <a href="../flow/begin-work/update-host-text.html">
            
                    
                    updateHostText
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.8" data-path="../feature/Suspense-component.md">
            
                <span>
            
                    
                    updateSuspenseComponent
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.9" data-path="../flow/begin-work/update-portal-component.html">
            
                <a href="../flow/begin-work/update-portal-component.html">
            
                    
                    updatePortalComponent
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.10" data-path="../flow/begin-work/update-forward-ref.html">
            
                <a href="../flow/begin-work/update-forward-ref.html">
            
                    
                    updateForwardRef
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.11" data-path="../flow/begin-work/update-fragment.html">
            
                <a href="../flow/begin-work/update-fragment.html">
            
                    
                    updateFragment
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.12" data-path="../flow/begin-work/update-mode.html">
            
                <a href="../flow/begin-work/update-mode.html">
            
                    
                    updateMode
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.13" data-path="../flow/begin-work/update-profiler.html">
            
                <a href="../flow/begin-work/update-profiler.html">
            
                    
                    updateProfiler
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.14" data-path="../flow/begin-work/update-context-provider.html">
            
                <a href="../flow/begin-work/update-context-provider.html">
            
                    
                    updateContextProvider
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.15" data-path="../flow/begin-work/update-context-consumer.html">
            
                <a href="../flow/begin-work/update-context-consumer.html">
            
                    
                    updateContextConsumer
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.8" data-path="../flow/reconcile-children.html">
            
                <a href="../flow/reconcile-children.html">
            
                    
                    reconcileChildren
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.8.1" data-path="../flow/reconcile-children/single.html">
            
                <a href="../flow/reconcile-children/single.html">
            
                    
                    调和单个节点
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.8.2" data-path="../flow/reconcile-children/array.html">
            
                <a href="../flow/reconcile-children/array.html">
            
                    
                    调和列表
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    commit 阶段
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../commit-phase/commit-root.html">
            
                <a href="../commit-phase/commit-root.html">
            
                    
                    commitRoot
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../commit-phase/invokeGuardedCallback.html">
            
                <a href="../commit-phase/invokeGuardedCallback.html">
            
                    
                    invokeGuardedCallback
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../commit-phase/commitBeforeMutationLifecycles.html">
            
                <a href="../commit-phase/commitBeforeMutationLifecycles.html">
            
                    
                    commitBeforeMutationLifecycles
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../commit-phase/commit-all-host-effects.html">
            
                <a href="../commit-phase/commit-all-host-effects.html">
            
                    
                    commitAllHostEffects
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.4.1" data-path="../commit-phase/host-effects/CommitPlacement.html">
            
                <a href="../commit-phase/host-effects/CommitPlacement.html">
            
                    
                    commitPlacement
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4.2" data-path="../commit-phase/host-effects/CommitWork.html">
            
                <a href="../commit-phase/host-effects/CommitWork.html">
            
                    
                    commitWork
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4.3" data-path="../commit-phase/host-effects/CommitDeletion.html">
            
                <a href="../commit-phase/host-effects/CommitDeletion.html">
            
                    
                    commitDeletion
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../commit-phase/commit-all-lifecycles.html">
            
                <a href="../commit-phase/commit-all-lifecycles.html">
            
                    
                    commitAllLifecycle
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" >
            
                <span>
            
                    
                    功能
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../features/context.html">
            
                <a href="../features/context.html">
            
                    
                    context
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../features/hydrate.html">
            
                <a href="../features/hydrate.html">
            
                    
                    hydrate
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../features/ref.html">
            
                <a href="../features/ref.html">
            
                    
                    ref
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../features/event-injection.html">
            
                <a href="../features/event-injection.html">
            
                    
                    事件系统初始化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../features/event-bind.html">
            
                <a href="../features/event-bind.html">
            
                    
                    事件绑定
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../features/event-dispatch.html">
            
                <a href="../features/event-dispatch.html">
            
                    
                    事件触发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../features/event-create-event-object.html">
            
                <a href="../features/event-create-event-object.html">
            
                    
                    事件对象生成
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="../features/Suspense-component.html">
            
                <a href="../features/Suspense-component.html">
            
                    
                    Suspense
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="../features/suspense.html">
            
                <a href="../features/suspense.html">
            
                    
                    挂起任务的含义
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.10" data-path="../features/suspense-lazy.html">
            
                <a href="../features/suspense-lazy.html">
            
                    
                    lazy 组件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" >
            
                <span>
            
                    
                    Hooks
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../hooks/hooks-start.html">
            
                <a href="../hooks/hooks-start.html">
            
                    
                    开始
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../hooks/hooks-use-state.html">
            
                <a href="../hooks/hooks-use-state.html">
            
                    
                    useState
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../hooks/hooks-use-effect.html">
            
                <a href="../hooks/hooks-use-effect.html">
            
                    
                    useEffect
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../hooks/hooks-others.html">
            
                <a href="../hooks/hooks-others.html">
            
                    
                    其他API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="../hooks/hooks-common.html">
            
                <a href="../hooks/hooks-common.html">
            
                    
                    通用API
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <form
            action="https://buttondown.email/api/emails/embed-subscribe/Jokcy"
            method="post"
            target="popupwindow"
            onsubmit="window.open('https://buttondown.email/Jokcy', 'popupwindow')"
            class="buttondown-form"
            >
            <input type="email" name="email" id="bd-email" placeholder="(your@email.com)">
            <input type="hidden" value="1" name="embed"/>
            <button type="submit">订阅我</button>
        </form>
    </li>
</ul>

                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                 
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >ReactDOM.render</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h3 id="reactdomrender">ReactDOM.render</h3><div class="api-method"><div class="api-method-definition"><h1 id="&#x5F00;&#x59CB;">&#x5F00;&#x59CB;</h1><p>&#x521B;&#x5EFA;<code>ReactRoot</code>&#xFF0C;&#x5E76;&#x4E14;&#x6839;&#x636E;&#x60C5;&#x51B5;&#x8C03;&#x7528;<code>root.legacy_renderSubtreeIntoContainer</code>&#x6216;&#x8005;<code>root.render</code>&#xFF0C;&#x524D;&#x8005;&#x662F;&#x9057;&#x7559;&#x7684; API &#x5C06;&#x6765;&#x5E94;&#x8BE5;&#x4F1A;&#x5220;&#x9664;&#xFF0C;&#x6839;&#x636E;<code>ReactDOM.render</code>&#x7684;&#x8C03;&#x7528;&#x60C5;&#x51B5;&#x4E5F;&#x53EF;&#x4EE5;&#x53D1;&#x73B0;<code>parentComponent</code>&#x662F;&#x5199;&#x6B7B;&#x7684;<code>null</code></p><p><code>DOMRenderer.unbatchedUpdates</code>&#x5236;&#x5B9A;&#x4E0D;&#x4F7F;&#x7528;<code>batchedUpdates</code>&#xFF0C;&#x56E0;&#x4E3A;&#x8FD9;&#x662F;&#x521D;&#x6B21;&#x6E32;&#x67D3;&#xFF0C;&#x9700;&#x8981;&#x5C3D;&#x5FEB;&#x5B8C;&#x6210;&#x3002;</p></div><div class="api-method-code"><div class="api-method-sample" data-lang="js" data-name="JavaScript"><pre><code class="lang-js">ReactDOM = {
  render(
    element: React$Element&lt;any&gt;,
    container: DOMContainer,
    callback: ?<span class="hljs-built_in">Function</span>,
  ) {
    <span class="hljs-keyword">return</span> legacyRenderSubtreeIntoContainer(
      <span class="hljs-literal">null</span>,
      element,
      container,
      <span class="hljs-literal">false</span>,
      callback,
    )
  },
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">legacyRenderSubtreeIntoContainer</span>(<span class="hljs-params">
  parentComponent: ?React$Component&lt;any, any&gt;,
  children: ReactNodeList,
  container: DOMContainer,
  forceHydrate: boolean,
  callback: ?Function,
</span>) </span>{
  <span class="hljs-keyword">let</span> root: Root = (container._reactRootContainer: any)
  <span class="hljs-keyword">if</span> (!root) {
    <span class="hljs-comment">// Initial mount</span>
    root = container._reactRootContainer = legacyCreateRootFromDOMContainer(
      container,
      forceHydrate,
    )
    <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> callback === <span class="hljs-string">&apos;function&apos;</span>) {
      <span class="hljs-keyword">const</span> originalCallback = callback
      callback = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
        <span class="hljs-keyword">const</span> instance = DOMRenderer.getPublicRootInstance(root._internalRoot)
        originalCallback.call(instance)
      }
    }
    <span class="hljs-comment">// Initial mount should not be batched.</span>
    DOMRenderer.unbatchedUpdates(() =&gt; {
      <span class="hljs-keyword">if</span> (parentComponent != <span class="hljs-literal">null</span>) {
        <span class="hljs-comment">// &#x4E00;&#x822C;&#x4E0D;&#x4F1A;&#x51FA;&#x73B0;</span>
      } <span class="hljs-keyword">else</span> {
        root.render(children, callback)
      }
    })
  } <span class="hljs-keyword">else</span> {
    <span class="hljs-comment">// &#x6709;root&#x7684;&#x60C5;&#x51B5;</span>
  }
  <span class="hljs-keyword">return</span> DOMRenderer.getPublicRootInstance(root._internalRoot)
}</code></pre>
</div></div></div>



<div class="api-method"><div class="api-method-definition"><p>&#x9996;&#x5148;&#x4F1A;&#x521B;&#x5EFA;<code>ReactRoot</code>&#x5BF9;&#x8C61;&#xFF0C;&#x7136;&#x540E;&#x8C03;&#x7528;&#x4ED6;&#x7684;<code>render</code>&#x65B9;&#x6CD5;</p><p>&#x521B;&#x5EFA;<code>ReactRoot</code>&#x7684;&#x65F6;&#x5019;&#x4F1A;&#x8C03;&#x7528;<code>DOMRenderer.createContainer</code>&#x521B;&#x5EFA;<code>FiberRoot</code>&#xFF0C;&#x5728;&#x540E;&#x671F;&#x8C03;&#x5EA6;&#x66F4;&#x65B0;&#x7684;&#x8FC7;&#x7A0B;&#x4E2D;&#x8FD9;&#x4E2A;&#x8282;&#x70B9;&#x975E;&#x5E38;&#x91CD;&#x8981;</p><p>&#x8FD9;&#x4E24;&#x4E2A;&#x6570;&#x636E;&#x7ED3;&#x6784;&#x770B;<a href="../api/react-structure.html">&#x8FD9;&#x91CC;</a></p></div><div class="api-method-code"><div class="api-method-sample" data-lang="js" data-name="JavaScript"><pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">legacyCreateRootFromDOMContainer</span>(<span class="hljs-params">
  container: DOMContainer,
  forceHydrate: boolean,
</span>): <span class="hljs-title">Root</span> </span>{
  <span class="hljs-keyword">const</span> shouldHydrate =
    forceHydrate || shouldHydrateDueToLegacyHeuristic(container)
  <span class="hljs-comment">// First clear any existing content.</span>
  <span class="hljs-keyword">if</span> (!shouldHydrate) {
    <span class="hljs-keyword">let</span> warned = <span class="hljs-literal">false</span>
    <span class="hljs-keyword">let</span> rootSibling
    <span class="hljs-keyword">while</span> ((rootSibling = container.lastChild)) {
      container.removeChild(rootSibling)
    }
  }
  <span class="hljs-comment">// Legacy roots are not async by default.</span>
  <span class="hljs-keyword">const</span> isConcurrent = <span class="hljs-literal">false</span>
  <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> ReactRoot(container, isConcurrent, shouldHydrate)
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">ReactRoot</span>(<span class="hljs-params">
  container: Container,
  isConcurrent: boolean,
  hydrate: boolean,
</span>) </span>{
  <span class="hljs-keyword">const</span> root = DOMRenderer.createContainer(container, isConcurrent, hydrate)
  <span class="hljs-keyword">this</span>._internalRoot = root
}

ReactRoot.prototype.render = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">
  children: ReactNodeList,
  callback: ?(</span>) =&gt; <span class="hljs-title">mixed</span>,
): <span class="hljs-title">Work</span> </span>{
  <span class="hljs-keyword">const</span> root = <span class="hljs-keyword">this</span>._internalRoot
  <span class="hljs-keyword">const</span> work = <span class="hljs-keyword">new</span> ReactWork()
  callback = callback === <span class="hljs-literal">undefined</span> ? <span class="hljs-literal">null</span> : callback
  <span class="hljs-keyword">if</span> (__DEV__) {
    warnOnInvalidCallback(callback, <span class="hljs-string">&apos;render&apos;</span>)
  }
  <span class="hljs-keyword">if</span> (callback !== <span class="hljs-literal">null</span>) {
    work.then(callback)
  }
  DOMRenderer.updateContainer(children, root, <span class="hljs-literal">null</span>, work._onCommit)
  <span class="hljs-keyword">return</span> work
}</code></pre>
</div></div></div>



<div class="api-method"><div class="api-method-definition"><p>&#x5176;&#x4E2D;<code>DOMRenderer</code>&#x662F;<code>react-reconciler/src/ReactFiberReconciler</code>&#xFF0C;&#x4ED6;&#x7684;<code>updateContainer</code>&#x5982;&#x4E0B;&#x5728;&#x8FD9;&#x91CC;&#x8BA1;&#x7B97;&#x4E86;&#x4E00;&#x4E2A;&#x65F6;&#x95F4;&#xFF0C;&#x8FD9;&#x4E2A;&#x65F6;&#x95F4;&#x53EB;&#x505A;<code>expirationTime</code>&#xFF0C;&#x987E;&#x540D;&#x601D;&#x4E49;&#x5C31;&#x662F;&#x8FD9;&#x6B21;&#x66F4;&#x65B0;&#x7684; <strong>&#x8D85;&#x65F6;&#x65F6;&#x95F4;</strong>&#x3002;</p><p>&#x5173;&#x4E8E;&#x65F6;&#x95F4;&#x662F;&#x5982;&#x4F55;&#x8BA1;&#x7B97;&#x7684;<a href="expiration-time.html">&#x770B;&#x8FD9;&#x91CC;</a></p><p>&#x7136;&#x540E;&#x8C03;&#x7528;&#x4E86;<code>updateContainerAtExpirationTime</code>&#xFF0C;&#x5728;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x91CC;&#x8C03;&#x7528;&#x4E86;<code>scheduleRootUpdate</code>&#x5C31;&#x975E;&#x5E38;&#x91CD;&#x8981;&#x4E86;</p></div><div class="api-method-code"><div class="api-method-sample" data-lang="js" data-name="JavaScript"><pre><code class="lang-js"><span class="hljs-keyword">export</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">updateContainer</span>(<span class="hljs-params">
  element: ReactNodeList,
  container: OpaqueRoot,
  parentComponent: ?React$Component&lt;any, any&gt;,
  callback: ?Function,
</span>): <span class="hljs-title">ExpirationTime</span> </span>{
  <span class="hljs-keyword">const</span> current = container.current
  <span class="hljs-keyword">const</span> currentTime = requestCurrentTime()
  <span class="hljs-keyword">const</span> expirationTime = computeExpirationForFiber(currentTime, current)
  <span class="hljs-keyword">return</span> updateContainerAtExpirationTime(
    element,
    container,
    parentComponent,
    expirationTime,
    callback,
  )
}

<span class="hljs-keyword">export</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">updateContainerAtExpirationTime</span>(<span class="hljs-params">
  element: ReactNodeList,
  container: OpaqueRoot,
  parentComponent: ?React$Component&lt;any, any&gt;,
  expirationTime: ExpirationTime,
  callback: ?Function,
</span>) </span>{
  <span class="hljs-comment">// <span class="hljs-doctag">TODO:</span> If this is a nested container, this won&apos;t be the root.</span>
  <span class="hljs-keyword">const</span> current = container.current
  <span class="hljs-keyword">const</span> context = getContextForSubtree(parentComponent)
  <span class="hljs-keyword">if</span> (container.context === <span class="hljs-literal">null</span>) {
    container.context = context
  } <span class="hljs-keyword">else</span> {
    container.pendingContext = context
  }

  <span class="hljs-keyword">return</span> scheduleRootUpdate(current, element, expirationTime, callback)
}</code></pre>
</div></div></div>



<div class="api-method"><div class="api-method-definition"><h1 id="&#x5F00;&#x59CB;&#x8C03;&#x5EA6;">&#x5F00;&#x59CB;&#x8C03;&#x5EA6;</h1><p>&#x9996;&#x5148;&#x8981;&#x751F;&#x6210;&#x4E00;&#x4E2A;<code>update</code>&#xFF0C;&#x4E0D;&#x7BA1;&#x4F60;&#x662F;<code>setState</code>&#x8FD8;&#x662F;<code>ReactDOM.render</code>&#x9020;&#x6210;&#x7684; React &#x66F4;&#x65B0;&#xFF0C;&#x90FD;&#x4F1A;&#x751F;&#x6210;&#x4E00;&#x4E2A;&#x53EB;<code>update</code>&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x5E76;&#x4E14;&#x4F1A;&#x8D4B;&#x503C;&#x7ED9;<code>Fiber.updateQueue</code></p><p>&#x5173;&#x4E8E;<code>update</code>&#x8BF7;<a href="../api/react-structure.html">&#x770B;&#x8FD9;&#x91CC;</a></p><p>&#x7136;&#x540E;&#x5C31;&#x662F;&#x8C03;&#x7528;<code>scheduleWork</code>&#x3002;&#x6CE8;&#x610F;&#x5230;&#x8FD9;&#x91CC;&#x4E4B;&#x524D;<code>setState</code>&#x548C;<code>ReactDOM.render</code>&#x662F;&#x4E0D;&#x4E00;&#x6837;&#xFF0C;&#x4F46;&#x8FDB;&#x5165;<code>schedulerWork</code>&#x4E4B;&#x540E;&#xFF0C;&#x5C31;&#x662F;&#x4EFB;&#x52A1;&#x8C03;&#x5EA6;&#x7684;&#x4E8B;&#x60C5;&#x4E86;&#xFF0C;&#x8DDF;&#x4E4B;&#x524D;&#x4F60;&#x662F;&#x600E;&#x4E48;&#x8C03;&#x7528;&#x7684;&#x6CA1;&#x6709;&#x4EFB;&#x4F55;&#x5173;&#x7CFB;</p></div><div class="api-method-code"><div class="api-method-sample" data-lang="js" data-name="JavaScript"><pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">scheduleRootUpdate</span>(<span class="hljs-params">
  current: Fiber,
  element: ReactNodeList,
  expirationTime: ExpirationTime,
  callback: ?Function,
</span>) </span>{
  <span class="hljs-keyword">const</span> update = createUpdate(expirationTime)

  update.payload = { element }

  callback = callback === <span class="hljs-literal">undefined</span> ? <span class="hljs-literal">null</span> : callback
  <span class="hljs-keyword">if</span> (callback !== <span class="hljs-literal">null</span>) {
    warningWithoutStack(
      <span class="hljs-keyword">typeof</span> callback === <span class="hljs-string">&apos;function&apos;</span>,
      <span class="hljs-string">&apos;render(...): Expected the last optional `callback` argument to be a &apos;</span> +
        <span class="hljs-string">&apos;function. Instead received: %s.&apos;</span>,
      callback,
    )
    update.callback = callback
  }
  enqueueUpdate(current, update)

  scheduleWork(current, expirationTime)
  <span class="hljs-keyword">return</span> expirationTime
}</code></pre>
</div></div></div>




                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
<div id="disqus_thread"></div>
<script>
  /**
   *  RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS.
   *  LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables*/
  /*
var disqus_config = function () {
this.page.url = PAGE_URL;  // Replace PAGE_URL with your page's canonical URL variable
this.page.identifier = PAGE_IDENTIFIER; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
};
*/
  ;(function() {
    // DON'T EDIT BELOW THIS LINE
    var d = document,
      s = d.createElement('script')
    s.src = 'https://react-source-code.disqus.com/embed.js'
    s.setAttribute('data-timestamp', +new Date())
    ;(d.head || d.body).appendChild(s)
  })()
</script>
<noscript
  >Please enable JavaScript to view the
  <a href="https://disqus.com/?ref_noscript"
    >comments powered by Disqus.</a
  ></noscript
>

            </div>

            

        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"ReactDOM.render","level":"1.3.1","depth":2,"next":{"title":"setState & forceUpdate","level":"1.3.2","depth":2,"path":"book/update/set-state.md","ref":"book/update/set-state.md","articles":[]},"previous":{"title":"创建更新","level":"1.3","depth":1,"ref":"","articles":[{"title":"ReactDOM.render","level":"1.3.1","depth":2,"path":"book/update/react-dom-render.md","ref":"book/update/react-dom-render.md","articles":[]},{"title":"setState & forceUpdate","level":"1.3.2","depth":2,"path":"book/update/set-state.md","ref":"book/update/set-state.md","articles":[]},{"title":"expirationTime 计算","level":"1.3.3","depth":2,"path":"book/update/expiration-time.md","ref":"book/update/expiration-time.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["theme-api"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"sharing":{"facebook":false,"twitter":false,"google":false,"weibo":true,"instapaper":false,"vk":false,"all":["weibo","google","twitter","weibo","instapaper"]},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-api":{"languages":[],"split":true,"theme":"light"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"React源码解析","language":"zh-hans","gitbook":"*"},"file":{"path":"book/update/react-dom-render.md","mtime":"2019-01-28T08:33:58.852Z","type":"markdown"},"gitbook":{"version":"3.2.0","time":"2019-07-08T12:28:32.264Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-theme-api/theme-api.js"></script>
        
    

    </body>
</html>

